﻿package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	
	/**
	 * ...
	 * @author Peter Tolstrup
	 */
	public class Main extends Sprite 
	{
		private static const WIDTH:int = 800;
		private static const HEIGHT:int = 600;
		
		private var _drawBitmapData:BitmapData;
		private var _drawBitmap:Bitmap;
		
		private var _noiseBitmapData:BitmapData;
		private var _noiseBitmap:Bitmap;
		private var _noiseOffset:Array;
		private var _noiseOffsetSpeed1:Number;
		private var _noiseOffsetSpeed2:Number;
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			_drawBitmapData = new BitmapData(WIDTH, HEIGHT)
			_drawBitmap = new Bitmap(_drawBitmapData);
			
			_noiseBitmapData = new BitmapData(WIDTH, HEIGHT);
			_noiseBitmap = new Bitmap(_noiseBitmapData);
			this.addChild(_noiseBitmap);
			
			_noiseOffset = [new Point(), new Point()];
			_noiseOffsetSpeed1 = 5.0;
			_noiseOffsetSpeed2 = -5.0;
			
			addEventListener(Event.ENTER_FRAME, update);
		}
		
		private function update(e:Event):void 
		{
			_noiseOffset[0].x += _noiseOffsetSpeed1;
			_noiseOffset[0].y += _noiseOffsetSpeed1;
			
			_noiseOffset[1].x += _noiseOffsetSpeed2;
			_noiseOffset[1].y += _noiseOffsetSpeed2;
			
			_noiseBitmapData.perlinNoise(WIDTH, HEIGHT, 14, 1,false, true, 1, true, _noiseOffset);			
		}		
	}	
}


internal class Particle 
{
	public function Particle()
	{
		
	}	
}
